package com.qibo.order;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.qibo.baselib.base.BaseActivity;
import com.qibo.order.adapter.MyPagerAdapter;

@Route(path = "/ordermodule/OrderMainActivity")
public class OrderMainActivity extends BaseActivity {
    private ImageButton imageButton;
    private TextView textView_titleBar;
    private TextView textView_Right_titleBar;
    private TabLayout mTablayout;
    private ViewPager mViewPager;
    /**全部*/
    public static final int ORDER_TYPE_ALL = 1;
    /**未付款*/
    public static final int ORDER_TYPE_AlREAD = 4;
    /**已付款*/
    public static final int ORDER_TYPE_CONSUME = 2;
    @Override
    protected int getContentViewId() {
        return R.layout.ordermodule_activity_main;
    }

    @Override
    protected void initView() {
        imageButton = findViewById(R.id.btnBack_pay1);
        textView_titleBar = findViewById(R.id.textView_titleBar);
        textView_Right_titleBar = findViewById(R.id.textView_Right_titleBar);
        mTablayout = findViewById(R.id.tab_layout);
        mViewPager = findViewById(R.id.viewpager);
        mViewPager.setOffscreenPageLimit(3);
        setupViewPager(mViewPager);
        mTablayout.addTab(mTablayout.newTab().setText(R.string.order_all));
        mTablayout.addTab(mTablayout.newTab().setText(R.string.order_receipt));
        mTablayout.addTab(mTablayout.newTab().setText(R.string.order_paidfor));
        mTablayout.setupWithViewPager(mViewPager);
    }

    @Override
    protected void initAction() {
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();;
            }
        });
        textView_titleBar.setText("订单");
    }

    @Override
    protected void initData() {

    }

    private void setupViewPager(ViewPager mViewPager) {
        //Fragment中嵌套使用Fragment一定要使用getChildFragmentManager(),否则会有问题
        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(OrderListFragment.newInstance(ORDER_TYPE_ALL), getString(R.string.order_all));
        adapter.addFragment(OrderListFragment.newInstance(ORDER_TYPE_AlREAD), getString(R.string.order_receipt));
        adapter.addFragment(OrderListFragment.newInstance(ORDER_TYPE_CONSUME), getString(R.string.order_paidfor));
        mViewPager.setAdapter(adapter);
    }
}
